/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package linkedlist;

/**
 *
 * @author Islam Hamdi
 */
public class MyLLIteratorD<T> {
private MyLinkedListD<T> list=new MyLinkedListD<T>();// a single linked list as instance variable.
	private NodeD<T> tracker;// pointer that tracks elements'
								// nodes.
	private NodeD<T> prevTracker;

	public MyLLIteratorD(MyLinkedListD<T> ls) {
		list = ls;
		tracker = list.getHeader();
		prevTracker = tracker;
	}

	/** returns true if the list still have elements. */
	public boolean hasNext() {
		if (tracker.getNext().getNext() != null) {
			return true;
		} else {
			return false;
		}
	}

	/** returns the next element of the list. */
	public T getNext() {
		prevTracker = tracker;
		tracker = tracker.getNext();
		return tracker.getElement();
	}

	/** returns true if the current node has a previous node */
	public boolean hasPrev() {
		if (prevTracker.getPrev().getPrev() != null) {
			return true;
		} else {
			return false;
		}
	}

	/** returns the previous node of the list */
	public T getPrev() {
		return prevTracker.getElement();
	}
}
